package AcWing;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

/**
 * @author ZhuYi
 * @create 2024/12/15 18:44
 */
public class 逆序对的数量 {
    static int N = 100010;
    static int[] arr = new int[N];

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int len = Integer.parseInt(br.readLine());
        String[] sarr = br.readLine().split(" ");
        for (int i = 0; i < len; i++) {
            arr[i] = Integer.parseInt(sarr[i]);
        }
        System.out.println(mergeSort(0, len - 1));
        br.close();
    }

    /**
     * 计算逆序对
     *
     * @param l
     * @param r
     * @return
     */
    static long mergeSort(int l, int r) {
        if (l >= r) return 0;
        int mid = (l + r) / 2;
        long res = 0;
        res += mergeSort(l, mid) + mergeSort(mid + 1, r);

        int[] tmp = new int[r - l + 1];
        int k = 0, i = l, j = mid + 1;
        while (i <= mid && j <= r) {
            if (arr[i] <= arr[j]) {
                tmp[k++] = arr[i++];
            } else {
                tmp[k++] = arr[j++];
                res += mid - i + 1;
            }
        }
        // 扫尾
        while (i <= mid) tmp[k++] = arr[i++];
        while (j <= r) tmp[k++] = arr[j++];

        // tmp -> arr
        for (i = l, j = 0; i <= r; i++, j++) {
            arr[i] = tmp[j];
        }
        return res;
    }
}
